package com.jt;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 金帮嘉诚 @date 2021-08-16 星期一 18:40
 */
@SpringBootApplication

public class ProviderApplication {
    //创建java中的日志对象(SLF4J是java中的日志规范,是日志对外的窗口,是门面)
    //目前市场上对SLF4J规范的实现主要有两种:log4j,logback
    private static final Logger log =
            LoggerFactory.getLogger(ProviderController.class);

    public static void main(String[] args) {
        SpringApplication.run(ProviderApplication.class, args);
    }

    /**
     * 定义Controller对象 (handler)
     * 基于此对象 处理客户端请求
     */
    @RestController
    public class ProviderController {
        //
        @Value("${server.port:8080}")
        private String port;

        //http://localhost:8081/provider/echo/tedu
        @GetMapping(value = "/provider/echo/{msg}")
        public String echo1(@PathVariable String msg) throws InterruptedException {
//            Thread.sleep(5000);
            // System.out.println("===");//耗时
            //日志级别trace<debug<info<warn<error
            //修改日志级别可以控制只输出当前和更高级别的日志
            //可以在配置文件修改日志级别,但是部署之后,这种方式需要暂停服务,就不可行
            //由此引入配置中心
            log.trace("==trace==");
            log.debug("==debug==");
            log.info("==info==");
            log.warn("==warn==");
            log.error("==error==");
            return "hello " + msg + "; server post is " + port;
        }
    }
}

